package com.addplus.townmall.server.api.mapper.town;

import com.addplus.townmall.server.api.model.town.ShopMemberStoreCart;
import com.addplus.townmall.server.api.model.town.expand.ShopMemberStoreCartExpand;
import com.addplus.townmall.server.api.model.town.expand.StoreExpand;
import com.addplus.townmall.server.api.utils.BaseAddMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 商城购物车店铺表 Mapper 接口
 * </p>
 *
 * @author zhangjiehang
 * @since 2018-10-24
 */
public interface ShopMemberStoreCartMapper extends BaseAddMapper<ShopMemberStoreCart> {

    @Select("SELECT\n" +
            " c.id,\n" +
            " s.id AS store_id,\n" +
            " s.store_name,\n" +
            " c.member_id \n" +
            "FROM\n" +
            " shop_member_store_cart c\n" +
            " LEFT JOIN store s ON s.id = c.store_id \n" +
            " AND s.store_status = 1 \n" +
            " AND s.is_delete = 0 \n" +
            "WHERE\n" +
            " c.member_id = #{memberId} \n" +
            " AND c.is_delete = 0 \n" +
            "ORDER BY\n" +
            " c.gmt_modified desc")
    List<ShopMemberStoreCartExpand> getShopMemberStorePage(Page page, @Param("memberId") Integer memberId);


    @Select("SELECT\n" +
            " store.id,\n" +
            " shop.store_id,\n" +
            " count(shop.store_id) as shop_count\n" +
            "FROM\n" +
            " shop_member_store_cart store\n" +
            " LEFT JOIN shop_member_shop_cart shop ON shop.store_id = store.store_id \n" +
            " AND shop.member_id = store.member_id \n" +
            " AND shop.is_delete = 0 \n" +
            "WHERE\n" +
            " store.member_id = #{memberId} \n" +
            " AND store.is_delete = 0\n" +
            "GROUP BY\n" +
            " shop.store_id,store.id \n" +
            "ORDER BY id ")
    List<ShopMemberStoreCartExpand> getShopCartStoreCount(@Param("memberId") Integer memberId);


}
